﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.BLL.Mtbl;
using HKEA.CMS.Core.BLL.Tbl;
using HKEA.CMS.Core.Utility;
using HKEA.CMS.Core.BLL.App;

namespace HKEA.CMS.Core.Models
{
    public class M_ContactPersonListDetail
    {
        public bool IsFromApp { get; set; }
        public int URLUID {
            get {
                if (IsFromApp)
                    return AppCustContactUID;
                else
                    return CustContactUID;
            }
        }
        public int AppCustContactUID { get; set; }
        public int CustContactUID { get; set; }
        public int AppContactPersonUID { get; set; }
        public int ContactPersonUID { get; set; }
        public string Position_Eng { get; set; }
        public string Position_Chi { get; set; }
        public string ChristianName { get; set; }
        public string FirstName_Eng { get; set; }
        public string LastName_Eng { get; set; }
        public string OtherTitle_Eng { get; set; }
        public string Salutation { get; set; }

        public string FirstName_Chi { get; set; }
        public string LastName_Chi { get; set; }
        public string OtherTitle_Chi { get; set; }

        public int AppAddressUID { get; set; }
        public int AddressUID { get; set; }

        public int InfoUID { get; set; }
        public int AppInfoUID { get; set; }

        public string strSpace { get { return ",&nbsp;"; } }

        public string SourceType { get; set; }

        private object obj = null;
        private tblContactInfo _info = null;
        private tblContactInfo GetinfoENT()
        {
            if (obj == null && !IsFromApp && InfoUID > 0)
            {
                tblContactInfo infoENT = new tblContactInfo();
                tblContactInfoBLL infoBLL = new tblContactInfoBLL();
                infoENT.ContactInfoUID = InfoUID;
                _info = infoBLL.GetEntity(infoENT);
                obj = new object();
            }
            return _info;
        }

        private object appobj = null;
        private app_tblContactInfo _appinfo = null;
        private app_tblContactInfo GetappinfoENT()
        {

            if (appobj == null && IsFromApp && AppInfoUID > 0)
            {
                app_tblContactInfo tempENT = null;
                tempENT = new app_tblContactInfo();
                app_tblContactInfoBLL infoBLL = new app_tblContactInfoBLL();
                tempENT.AppContactInfoUID = AppInfoUID;
                _appinfo = infoBLL.GetAppENTByENT(tempENT);
                appobj = new object();
            }
            return _appinfo;
        }
        public tblContactInfo InfoENT
        {
            get
            {
                return GetinfoENT();
            }
        }

        public app_tblContactInfo AppInfoENT
        {
            get
            {
                return GetappinfoENT();
            }
        }

        public mtblArea areaENT { get; set; }

        public mtblCountry countryENT { get; set; }

        public string strAddress
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();
                if (!IsFromApp)
                {
                    #region 从tbl表中取数据
                    tblAddressBLL bll = new tblAddressBLL();
                    tblAddress addressENT = new tblAddress();
                    addressENT.AddressUID = AddressUID;
                    addressENT = bll.GetEntity(addressENT);
                    if (addressENT != null)
                    {
                        countryENT = addressENT.mtblCountry;
                        if (addressENT.mtblCountry != null)
                        {
                            mtblArea area = new mtblArea();
                            mtblAreaBLL areaBLL = new mtblAreaBLL();
                            area.AreaUID = (int)addressENT.mtblCountry.AreaUID;
                            area.Deleted = 0;
                            areaENT = areaBLL.GetEntity(area);
                        }


                        if (!string.IsNullOrEmpty(addressENT.Flat_Bldg_Eng))
                            strBuilder.Append(addressENT.Flat_Bldg_Eng).Append("&nbsp;");
                        if (!string.IsNullOrEmpty(addressENT.Street_Rd_Eng))
                            strBuilder.Append(addressENT.Street_Rd_Eng).Append("&nbsp;");
                        if (!string.IsNullOrEmpty(addressENT.Area_Eng))
                            strBuilder.Append(addressENT.Area_Eng).Append("&nbsp;");
                        if (!string.IsNullOrEmpty(addressENT.District_Eng))
                            strBuilder.Append(addressENT.District_Eng).Append("&nbsp;");

                        #region 英文 City、Province、Country过滤
                        if (!string.IsNullOrEmpty(addressENT.City_Eng) && !string.IsNullOrEmpty(addressENT.Province_Eng) && addressENT.City_Eng.ToLower().Trim() == addressENT.Province_Eng.ToLower().Trim())
                        {
                            strBuilder.Append(addressENT.City_Eng.Trim()).Append("&nbsp;");
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(addressENT.City_Eng))
                                strBuilder.Append(addressENT.City_Eng.Trim()).Append("&nbsp;");
                            if (!string.IsNullOrEmpty(addressENT.Province_Eng))
                                strBuilder.Append(addressENT.Province_Eng.Trim()).Append("&nbsp;");
                        }
                        if (countryENT != null)
                        {
                            string strCounrtyEng = countryENT.Country_Eng;
                            if (!string.IsNullOrEmpty(addressENT.Province_Eng) && !string.IsNullOrEmpty(strCounrtyEng) && addressENT.Province_Eng.ToLower().Trim() == strCounrtyEng.ToLower().Trim())
                            {
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(addressENT.Province_Eng) && !string.IsNullOrEmpty(strCounrtyEng) && !string.IsNullOrEmpty(addressENT.City_Eng) && strCounrtyEng.ToLower().Trim() == addressENT.City_Eng.ToLower().Trim())
                                {
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(strCounrtyEng))
                                    {
                                        strBuilder.Append(strCounrtyEng.Trim()).Append("&nbsp;");
                                    }
                                }
                            }
                        }
                        if (areaENT != null)
                        {
                            if (!string.IsNullOrEmpty(areaENT.Area_Eng))
                            {
                                strBuilder.Append(areaENT.Area_Eng.Trim()).Append("&nbsp;");
                            }
                        }
                        #endregion

                        strBuilder.Append("<br/>");

                        if (areaENT != null)
                        {
                            if (!string.IsNullOrEmpty(areaENT.Area_Chi))
                                strBuilder.Append(areaENT.Area_Chi);
                        }
                        string strCountryChi = string.Empty;
                        string CityChi = addressENT.City_Chi;
                        string ProvinceChi = addressENT.Province_Chi;
                        if (countryENT != null)
                        {
                            strCountryChi = countryENT.Country_Chi;
                        }



                        if (!string.IsNullOrEmpty(strCountryChi))
                        {
                            strBuilder.Append(strCountryChi.Trim());
                            if (!string.IsNullOrEmpty(ProvinceChi))
                            {
                                if (strCountryChi.ToLower().Trim() != ProvinceChi.ToLower().Trim())
                                {
                                    strBuilder.Append(ProvinceChi.Trim());
                                    if (!string.IsNullOrEmpty(CityChi) && CityChi.ToLower().Trim() != ProvinceChi.ToLower().Trim())
                                        strBuilder.Append(CityChi.Trim());
                                }
                            }
                            else //省份为空
                            {
                                if (!string.IsNullOrEmpty(CityChi) && CityChi.ToLower().Trim() != strCountryChi.ToLower().Trim())
                                    strBuilder.Append(CityChi.Trim());
                            }
                        }
                        else //国家为空
                        {
                            if (!string.IsNullOrEmpty(ProvinceChi))
                            {
                                strBuilder.Append(ProvinceChi.Trim());
                                if (!string.IsNullOrEmpty(CityChi) && CityChi.ToLower().Trim() != ProvinceChi.ToLower().ToLower())
                                {
                                    strBuilder.Append(CityChi.Trim());
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(CityChi))
                                    strBuilder.Append(CityChi.Trim());
                            }
                        }
                        if (!string.IsNullOrEmpty(addressENT.District_Chi))
                            strBuilder.Append(addressENT.District_Chi);
                        if (!string.IsNullOrEmpty(addressENT.Area_Chi))
                            strBuilder.Append(addressENT.Area_Chi);
                        if (!string.IsNullOrEmpty(addressENT.Street_Rd_Chi))
                            strBuilder.Append(addressENT.Street_Rd_Chi);
                        if (!string.IsNullOrEmpty(addressENT.Flat_Bldg_Chi))
                            strBuilder.Append(addressENT.Flat_Bldg_Chi);
                    }
                    #endregion 
                }
                else
                {
                    #region 从 app表中取数据
                    app_tblAddress addressENT = new app_tblAddress();
                    app_tblAddressBLL bll = new app_tblAddressBLL();
                    addressENT.AppAddressUID = AppAddressUID;
                    addressENT = bll.GetAppENTByENT(addressENT);
                    if (addressENT != null)
                    {
                        countryENT = addressENT.mtblCountry;
                        if (addressENT.mtblCountry != null)
                        {
                            mtblArea area = new mtblArea();
                            mtblAreaBLL areaBLL = new mtblAreaBLL();
                            area.AreaUID = (int)addressENT.mtblCountry.AreaUID;
                            area.Deleted = 0;
                            areaENT = areaBLL.GetEntity(area);
                        }


                        if (!string.IsNullOrEmpty(addressENT.Flat_Bldg_Eng))
                            strBuilder.Append(addressENT.Flat_Bldg_Eng).Append("&nbsp;");
                        if (!string.IsNullOrEmpty(addressENT.Street_Rd_Eng))
                            strBuilder.Append(addressENT.Street_Rd_Eng).Append("&nbsp;");
                        if (!string.IsNullOrEmpty(addressENT.Area_Eng))
                            strBuilder.Append(addressENT.Area_Eng).Append("&nbsp;");
                        if (!string.IsNullOrEmpty(addressENT.District_Eng))
                            strBuilder.Append(addressENT.District_Eng).Append("&nbsp;");

                        #region 英文 City、Province、Country过滤
                        if (!string.IsNullOrEmpty(addressENT.City_Eng) && !string.IsNullOrEmpty(addressENT.Province_Eng) && addressENT.City_Eng.ToLower().Trim() == addressENT.Province_Eng.ToLower().Trim())
                        {
                            strBuilder.Append(addressENT.City_Eng.Trim()).Append("&nbsp;");
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(addressENT.City_Eng))
                                strBuilder.Append(addressENT.City_Eng.Trim()).Append("&nbsp;");
                            if (!string.IsNullOrEmpty(addressENT.Province_Eng))
                                strBuilder.Append(addressENT.Province_Eng.Trim()).Append("&nbsp;");
                        }
                        if (countryENT != null)
                        {
                            string strCounrtyEng = countryENT.Country_Eng;
                            if (!string.IsNullOrEmpty(addressENT.Province_Eng) && !string.IsNullOrEmpty(strCounrtyEng) && addressENT.Province_Eng.ToLower().Trim() == strCounrtyEng.ToLower().Trim())
                            {
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(addressENT.Province_Eng) && !string.IsNullOrEmpty(strCounrtyEng) && !string.IsNullOrEmpty(addressENT.City_Eng) && strCounrtyEng.ToLower().Trim() == addressENT.City_Eng.ToLower().Trim())
                                {
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(strCounrtyEng))
                                    {
                                        strBuilder.Append(strCounrtyEng.Trim()).Append("&nbsp;");
                                    }
                                }
                            }
                        }
                        if (areaENT != null)
                        {
                            if (!string.IsNullOrEmpty(areaENT.Area_Eng))
                            {
                                strBuilder.Append(areaENT.Area_Eng.Trim()).Append("&nbsp;");
                            }
                        }
                        #endregion

                        strBuilder.Append("<br/>");

                        if (areaENT != null)
                        {
                            if (!string.IsNullOrEmpty(areaENT.Area_Chi))
                                strBuilder.Append(areaENT.Area_Chi);
                        }
                        string strCountryChi = string.Empty;
                        string CityChi = addressENT.City_Chi;
                        string ProvinceChi = addressENT.Province_Chi;
                        if (countryENT != null)
                        {
                            strCountryChi = countryENT.Country_Chi;
                        }



                        if (!string.IsNullOrEmpty(strCountryChi))
                        {
                            strBuilder.Append(strCountryChi.Trim());
                            if (!string.IsNullOrEmpty(ProvinceChi))
                            {
                                if (strCountryChi.ToLower().Trim() != ProvinceChi.ToLower().Trim())
                                {
                                    strBuilder.Append(ProvinceChi.Trim());
                                    if (!string.IsNullOrEmpty(CityChi) && CityChi.ToLower().Trim() != ProvinceChi.ToLower().Trim())
                                        strBuilder.Append(CityChi.Trim());
                                }
                            }
                            else //省份为空
                            {
                                if (!string.IsNullOrEmpty(CityChi) && CityChi.ToLower().Trim() != strCountryChi.ToLower().Trim())
                                    strBuilder.Append(CityChi.Trim());
                            }
                        }
                        else //国家为空
                        {
                            if (!string.IsNullOrEmpty(ProvinceChi))
                            {
                                strBuilder.Append(ProvinceChi.Trim());
                                if (!string.IsNullOrEmpty(CityChi) && CityChi.ToLower().Trim() != ProvinceChi.ToLower().ToLower())
                                {
                                    strBuilder.Append(CityChi.Trim());
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(CityChi))
                                    strBuilder.Append(CityChi.Trim());
                            }
                        }
                        if (!string.IsNullOrEmpty(addressENT.District_Chi))
                            strBuilder.Append(addressENT.District_Chi);
                        if (!string.IsNullOrEmpty(addressENT.Area_Chi))
                            strBuilder.Append(addressENT.Area_Chi);
                        if (!string.IsNullOrEmpty(addressENT.Street_Rd_Chi))
                            strBuilder.Append(addressENT.Street_Rd_Chi);
                        if (!string.IsNullOrEmpty(addressENT.Flat_Bldg_Chi))
                            strBuilder.Append(addressENT.Flat_Bldg_Chi);
                    }
                    #endregion
                }
                str = strBuilder.ToString();
                return str;
            }
        }
        
        public string Email
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();
                if (IsFromApp && AppInfoENT != null)
                {
                    if (!string.IsNullOrEmpty(AppInfoENT.Email1))
                        strBuilder.Append(AppInfoENT.Email1).Append(strSpace);
                    if (!string.IsNullOrEmpty(AppInfoENT.Email2))
                        strBuilder.Append(AppInfoENT.Email2).Append(strSpace);
                    if (!string.IsNullOrEmpty(AppInfoENT.Email3))
                        strBuilder.Append(AppInfoENT.Email3).Append(strSpace);
                    if (!string.IsNullOrEmpty(AppInfoENT.Email4))
                        strBuilder.Append(AppInfoENT.Email4).Append(strSpace);
                    if (!string.IsNullOrEmpty(AppInfoENT.Email5))
                        strBuilder.Append(AppInfoENT.Email5).Append(strSpace);
                    str = strBuilder.ToString();
                    if (str.Length > 0)
                        str = str.Substring(0, str.Length - strSpace.Length);
                }
                else
                {
                    if (InfoENT != null)
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Email1))
                            strBuilder.Append(InfoENT.Email1).Append(strSpace);
                        if (!string.IsNullOrEmpty(InfoENT.Email2))
                            strBuilder.Append(InfoENT.Email2).Append(strSpace);
                        if (!string.IsNullOrEmpty(InfoENT.Email3))
                            strBuilder.Append(InfoENT.Email3).Append(strSpace);
                        if (!string.IsNullOrEmpty(InfoENT.Email4))
                            strBuilder.Append(InfoENT.Email4).Append(strSpace);
                        if (!string.IsNullOrEmpty(InfoENT.Email5))
                            strBuilder.Append(InfoENT.Email5).Append(strSpace);
                        str = strBuilder.ToString();
                        if (str.Length > 0)
                            str = str.Substring(0, str.Length - strSpace.Length);
                    }
                }
                return str;
            }
        }

        public string WebSite
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();
                if (IsFromApp && AppInfoENT != null)
                {
                    if (!string.IsNullOrEmpty(AppInfoENT.Website1))
                        strBuilder.Append(AppInfoENT.Website1).Append(strSpace);
                    if (!string.IsNullOrEmpty(AppInfoENT.Website2))
                        strBuilder.Append(AppInfoENT.Website2).Append(strSpace);
                    str = strBuilder.ToString();
                    if (str.Length > 0)
                        str = str.Substring(0, str.Length - strSpace.Length);
                }
                else if(InfoENT!=null)
                {
                    if (!string.IsNullOrEmpty(InfoENT.Website1))
                        strBuilder.Append(InfoENT.Website1).Append(strSpace);
                    if (!string.IsNullOrEmpty(InfoENT.Website2))
                        strBuilder.Append(InfoENT.Website2).Append(strSpace);
                    str = strBuilder.ToString();
                    if (str.Length > 0)
                        str = str.Substring(0, str.Length - strSpace.Length);
                }
                return str;
            }
        }

        public string strTel
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();
                if (IsFromApp && AppInfoENT != null)
                {
                    #region
                    if (!string.IsNullOrEmpty(AppInfoENT.Tel1))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel1_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel1_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel1_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel1_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Tel1).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Tel2))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel2_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel2_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel2_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel2_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Tel2).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Tel3))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel3_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel3_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel3_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel3_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Tel3).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Tel4))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel4_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel4_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel4_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel4_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Tel4).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Tel5))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel5_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel5_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Tel5_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Tel5_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Tel5).Append(strSpace);
                    }
                    #endregion
                }
                else if(InfoENT!=null)
                {
                     #region
                    if (!string.IsNullOrEmpty(InfoENT.Tel1))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Tel1_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Tel1_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Tel1_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Tel1_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Tel1).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Tel2))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Tel2_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Tel2_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Tel2_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Tel2_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Tel2).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Tel3))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Tel3_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Tel3_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Tel3_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Tel3_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Tel3).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Tel4))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Tel4_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Tel4_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Tel4_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Tel4_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Tel4).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Tel5))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Tel5_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Tel5_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Tel5_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Tel5_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Tel5).Append(strSpace);
                    }
                    #endregion
                }
                str = strBuilder.ToString();
                    if (str.Length > 0)
                        str = str.Substring(0, str.Length - strSpace.Length);
                return str;
            }
        }

        public string strFax
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();
                if (IsFromApp && AppInfoENT != null)
                {
                    #region
                    if (!string.IsNullOrEmpty(AppInfoENT.Fax1))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax1_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax1_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax1_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax1_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Fax1).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Fax2))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax2_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax2_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax2_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax2_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Fax2).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Fax3))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax3_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax3_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax3_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax3_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Fax3).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Fax4))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax4_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax4_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax4_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax4_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Fax4).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(AppInfoENT.Fax5))
                    {
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax5_AreaCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax5_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(AppInfoENT.Fax5_CountryCode))
                            strBuilder.Append("(").Append(AppInfoENT.Fax5_CountryCode).Append(") ");
                        strBuilder.Append(AppInfoENT.Fax5).Append(strSpace);
                    }
                    #endregion
                }
                else if(InfoENT!=null)
                {
                     #region
                    if (!string.IsNullOrEmpty(InfoENT.Fax1))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Fax1_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Fax1_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Fax1_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Fax1_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Fax1).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Fax2))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Fax2_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Fax2_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Fax2_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Fax2_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Fax2).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Fax3))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Fax3_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Fax3_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Fax3_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Fax3_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Fax3).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Fax4))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Fax4_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Fax4_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Fax4_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Fax4_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Fax4).Append(strSpace);
                    }
                    if (!string.IsNullOrEmpty(InfoENT.Fax5))
                    {
                        if (!string.IsNullOrEmpty(InfoENT.Fax5_AreaCode))
                            strBuilder.Append("(").Append(InfoENT.Fax5_AreaCode).Append(") ");
                        if (!string.IsNullOrEmpty(InfoENT.Fax5_CountryCode))
                            strBuilder.Append("(").Append(InfoENT.Fax5_CountryCode).Append(") ");
                        strBuilder.Append(InfoENT.Fax5).Append(strSpace);
                    }
                    #endregion
                }
                str = strBuilder.ToString();
                    if (str.Length > 0)
                        str = str.Substring(0, str.Length - strSpace.Length);
                return str;
            }
        }

        public string FullName
        {
            get
            {
                return string.Format("{0} {1} {2} {3} {4} {5}&nbsp;&nbsp;{6} {7} {8} {9}", Salutation, ChristianName, FirstName_Eng, LastName_Eng, OtherTitle_Eng, Position_Eng , LastName_Chi, FirstName_Chi, OtherTitle_Chi,Position_Chi);
            }
        }

        public string FullNameAndImg
        {
            get
            {
                string str = string.Empty;
                string strImgUrl = string.Empty;
                if (IsFromApp)
                {
                    app_tblMediaRoom_Related app_related = new app_tblMediaRoom_Related();
                    app_tblMediaRoom_RelatedBLL app_relatedBLL = new app_tblMediaRoom_RelatedBLL();
                    app_related.Category = Constant.MediaRoomCategory.contactperson_photo;
                    app_related.AppRelatedUID = AppContactPersonUID;
                    app_related.Deleted = 0;

                    var tempList = app_relatedBLL.GetListByENT(app_related);
                    if (tempList != null && tempList.Where(a => a.Deleted == 0).ToList().Count > 0)
                    {
                        strImgUrl = "<img src=\"/Media/Css/images/cphsmedia.png\" />";
                    }
                    str = string.Format("{0} {1}", FullName, strImgUrl);
                }
                tblMediaRoomRelatedBLL relatedBLL = new tblMediaRoomRelatedBLL();
                tblMediaRoom_Related related = new tblMediaRoom_Related();
                related.Category = Constant.MediaRoomCategory.contactperson_photo;
                related.RelatedUID = ContactPersonUID;
                related.Deleted = 0;
                if (relatedBLL.GetEntity(related) != null)
                {
                    strImgUrl = "<img src=\"/Media/Css/images/cphsmedia.png\" />";
                }
                str = string.Format("{0} {1}", FullName, strImgUrl);
                return str;
            }
        }

        public string strJobNature
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();
                if (IsFromApp)
                {
                    app_tblCPerson_JobNatureBLL appBLL = new app_tblCPerson_JobNatureBLL();
                    app_tblCPerson_JobNature appENT = new app_tblCPerson_JobNature();
                    appENT.AppContactPersonUID = AppContactPersonUID;
                    appENT.Deleted = 0;
                    var AllApplist = appBLL.GetListByENT(appENT, false);

                    var app_list = AllApplist.Where(a => a.Deleted == 0).ToList();
                    var tbl_withOutList = AllApplist.Where(a => a.ContactPersonUID > 0).Where(a=>a.CPerson_JobNatureUID > 0).ToList().Select(a => (int)a.CPerson_JobNatureUID).ToList();
                    foreach (var temp in app_list)
                    {
                        string strEng = temp.mtblJobNature.JobNature_Eng;
                        string strChi = temp.mtblJobNature.JobNature_Chi;
                        if (!string.IsNullOrEmpty(strEng))
                            strBuilder.Append(strEng);
                        if (!string.IsNullOrEmpty(strChi))
                            strBuilder.Append("&nbsp;").Append(strChi);
                        strBuilder.Append(strSpace);
                    }
                    if (ContactPersonUID > 0)
                    {
                        tblCPerson_JobNatureBLL tblBLL = new tblCPerson_JobNatureBLL();
                        tblCPerson_JobNature tblENT = new tblCPerson_JobNature();
                        tblENT.ContactPersonUID = ContactPersonUID;
                        tblENT.Deleted = 0;
                        var tbl_list=tblBLL.GetList(tblENT, tbl_withOutList);
                        foreach (var temp in tbl_list)
                        {
                            string strEng = temp.mtblJobNature.JobNature_Eng;
                            string strChi = temp.mtblJobNature.JobNature_Chi;
                            if (!string.IsNullOrEmpty(strEng))
                                strBuilder.Append(strEng);
                            if (!string.IsNullOrEmpty(strChi))
                                strBuilder.Append("&nbsp;").Append(strChi);
                            strBuilder.Append(strSpace);
                        }
                    }
                }
                else
                {
                    tblCPerson_JobNature jobNature = new tblCPerson_JobNature();
                    tblCPerson_JobNatureBLL bll = new tblCPerson_JobNatureBLL();
                    jobNature.ContactPersonUID = ContactPersonUID;
                    jobNature.Deleted = 0;
                    var list = bll.GetListByENT(jobNature);
                    foreach (var temp in list)
                    {
                        string strEng = temp.mtblJobNature.JobNature_Eng;
                        string strChi = temp.mtblJobNature.JobNature_Chi;
                        if (!string.IsNullOrEmpty(strEng))
                            strBuilder.Append(strEng);
                        if (!string.IsNullOrEmpty(strChi))
                            strBuilder.Append("&nbsp;").Append(strChi);
                        strBuilder.Append(strSpace);
                    }
                }
                str = strBuilder.ToString();
                if (str.Length > 0)
                    str = str.Substring(0, str.Length - strSpace.Length);
                return str;
            }
        }

        public string strCommitteeMember
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();

                app_tblCPerson_CommMember appENT = new app_tblCPerson_CommMember();
                app_tblCPerson_CommMemberBLL appBLL = new app_tblCPerson_CommMemberBLL();
                tblCPerson_CommMemberBLL tblBLL = new tblCPerson_CommMemberBLL();
                List<CommitteeMemberList> appAllList = new List<CommitteeMemberList>();
                List<CommitteeMemberList> listValue = new List<CommitteeMemberList>();
                int app_cpuid = AppContactPersonUID;
                int cpuid = ContactPersonUID;
                if (app_cpuid > 0 || cpuid > 0)
                {
                    app_tblCPerson_CommMember app_comm = new app_tblCPerson_CommMember();
                    app_comm.AppContactPersonUID = app_cpuid;
                    app_comm.ContactPersonUID = cpuid;
                    appAllList = appBLL.GetList(app_comm, false);
                }
                List<CommitteeMemberList> appData = appAllList.Where(a => a.IsDeleted == 0).ToList();

                List<int> withOutList = new List<int>();
                foreach (var temp in appAllList.Where(a => a.TblKeyUID > 0).ToList())
                {
                    withOutList.Add(temp.TblKeyUID);
                }
                List<CommitteeMemberList> tblData = new List<CommitteeMemberList>();
                if (cpuid > 0)
                {
                    tblData = tblBLL.GetListByCPUID(cpuid, withOutList);
                }
                listValue.AddRange(tblData);
                listValue.AddRange(appData);
                foreach (var temp in listValue)
                {
                    var tempType = temp.mtblType;
                    var tempPosition = temp.mtblPosition ;
                    strBuilder.Append(tempType.CommType_Eng);
                    if (!string.IsNullOrEmpty(tempType.CommType_Chi))
                        strBuilder.Append("&nbsp;").Append(tempType.CommType_Chi);
                    strBuilder.Append(strSpace).Append(tempPosition.CommPosition_Eng);
                    if (!string.IsNullOrEmpty(tempPosition.CommPosition_Chi))
                        strBuilder.Append("&nbsp;").Append(tempPosition.CommPosition_Chi);
                }
                str = strBuilder.ToString();
                return str;
            }
        }

        public string strAttribute
        {
            get
            {
                string str = string.Empty;
                StringBuilder strBuilder = new StringBuilder();
                List<int> strlist = new List<int>();
                if (IsFromApp)
                {
                    app_tblCPerson_AttributeBLL appBLL = new app_tblCPerson_AttributeBLL();
                    app_tblCPerson_Attribute appENT = new app_tblCPerson_Attribute();
                    appENT.AppContactPersonUID = AppContactPersonUID;
                    appENT.Deleted = 0;
                    var AllApplist = appBLL.GetListByENT(appENT, false);

                    var app_list = AllApplist.Where(a => a.Deleted == 0).ToList();
                    foreach (var temp in app_list)
                    {
                        string strEng = temp.mtblAttribute.Attribute_Eng;
                        string strChi = temp.mtblAttribute.Attribute_Chi;
                        if (!string.IsNullOrEmpty(strEng))
                            strBuilder.Append(strEng);
                        if (!string.IsNullOrEmpty(strChi))
                            strBuilder.Append("&nbsp;").Append(strChi);
                        strBuilder.Append(strSpace);
                    }
                    var tbl_withOutList = AllApplist.Where(a => a.ContactPersonUID > 0).Where(a=>a.CPerson_AttributeUID > 0).ToList().Select(a => (int)a.CPerson_AttributeUID).ToList();
                    if (ContactPersonUID > 0)
                    {
                        tblCPerson_AttributeBLL tblBLL = new tblCPerson_AttributeBLL();
                        tblCPerson_Attribute tblENT = new tblCPerson_Attribute();
                        tblENT.ContactPersonUID = ContactPersonUID;
                        tblENT.Deleted = 0;
                        var tbl_list = tblBLL.GetList(tblENT, tbl_withOutList);
                        foreach (var temp in tbl_list)
                        {
                            strlist.Add((int)temp.AttributeUID);
                        }
                    }
                }
                else
                {
                    tblCPerson_AttributeBLL tblBLL = new tblCPerson_AttributeBLL();
                    tblCPerson_Attribute tblENT = new tblCPerson_Attribute();
                    tblENT.ContactPersonUID = ContactPersonUID;
                    tblENT.Deleted = 0;
                    var tbl_list = tblBLL.GetListByENT(tblENT);
                    foreach (var temp in tbl_list)
                    {
                        strlist.Add((int)temp.AttributeUID);
                    }
                }
                mtblAttributeBLL bll = new mtblAttributeBLL();
                strBuilder.Append(bll.GetAttrubuteByUID(strlist)).Append(strSpace);
                str = strBuilder.ToString();
                if (str.Length > 0)
                    str = str.Substring(0, str.Length - strSpace.Length);
                return str;
            }
        }
    }
}
